from flask import Flask
import settings
from flask_socketio import SocketIO


socketio = SocketIO()
    

def create_app():
    app = Flask(__name__, template_folder='../templates', static_folder='../static')  # app是一个核心对象
    app.config.from_object(settings)  # 加载配置

    app = app_register_all(app)

    socketio.init_app(app, cors_allowed_origins="*", async_mode='gevent')
    from apps.GPS.gps_event import state_monitor_thread
    state_monitor_thread()
    # print("app")
    return app


def app_register_all(app):          # 注册所有蓝图
    from apps.user.view import user_bp
    from apps.path.view import path_bp
    from apps.trailer.view import trailer_bp
    from apps.message import message_bp
    from apps import GPS
    from flasgger import Swagger
    Swagger(app)
    app.register_blueprint(message_bp)  # 导入message蓝图对象
    app.register_blueprint(user_bp)  # 导入user蓝图对象
    app.register_blueprint(trailer_bp)  # 导入trailer蓝图对象

    app.register_blueprint(path_bp)  # 导入path蓝图对象
    return app
